const reqlib = require('app-root-path').require
const numberUtil = reqlib('/app/util/numberUtil')
const btbAs = reqlib('/app/common/btb')

function kdjUpKeepTimes (list, days) {
  if (list.length <= days) {
    return false
  }
  let last = list.length - 1
  for (let i = 0; i < days; i++) {
    const emInfo = list[last - i]
    const kdjDiff = emInfo.kdj.J - emInfo.kdj.D
    if (kdjDiff < 0) {
      return false
    }
  }
  return true
}

module.exports = {
  // 止损
  stopLoss () {
    const btbLeverage = this.opConfig.btbLeverage
    // 两倍杠杆-5(-10)止损
    let cutLine = -5
    if (btbLeverage === 1) {
      // 一倍杠杆-6止损
      cutLine = -6
    }
    if (btbLeverage === 2) {
      cutLine = -5
    }
    if (btbLeverage === 3) {
      cutLine = -4
    }
    // 止损，不去影响买和卖的信号
    if (this.btbItem.incomeRate < cutLine) {
      // 持仓是空单，那么平空
      if (this.btbItem.usdt < -5) {
        this.pingKong = true
        this.pingKongReason = 'stopLoss'
      }
      // 持仓是多单，那么平多
      if (this.btbItem.usdt > 5) {
        this.pingDuo = true
        this.pingDuoReason = 'stopLoss'
      }
    }
  },
  // 巨大波动以后就平仓、关闭策略
  highWaveClear () {
    let highWaveClear = false
    const btbItem = this.btbItem
    const btbOpInfo = this.btbOpInfo
    const minute15EmaInfo = this.btbItem.minute15EmaInfo || {}
    // 巨大波动以后就关闭策
    let wave = numberUtil.countDifferenceRate(minute15EmaInfo.high, minute15EmaInfo.low)
    if (Math.abs(wave) >= (btbItem.avWave * 15)) {
      if (minute15EmaInfo.netChangeRatio < 0) {
        // 跌幅巨大
        btbOpInfo.highWaveStatus = 'down'
      } else if (minute15EmaInfo.netChangeRatio > 0) {
        // 涨幅巨大
        btbOpInfo.highWaveStatus = 'up'
      }
    }
    // 平空
    if (btbOpInfo.highWaveStatus === 'down' && minute15EmaInfo.netChangeRatio > 0) {
      btbOpInfo.highWaveStatus = ''
      this.pingKong = true
      this.pingDuo = false
      this.buy = false
      this.sell = false
      highWaveClear = true
      this.pingKongReason = 'highWaveClear'
    }
    // 平多
    if (btbOpInfo.highWaveStatus === 'up' && minute15EmaInfo.netChangeRatio < 0) {
      btbOpInfo.highWaveStatus = ''
      this.pingDuo = true
      this.pingKong = false
      this.buy = false
      this.sell = false
      highWaveClear = true
      this.pingDuoReason = 'highWaveClear'
    }
    // 一波macd涨了很多
    if (btbItem.macdUpHigh) {
      btbOpInfo.highWaveStatus = ''
      this.pingDuo = true
      this.pingKong = false
      this.buy = false
      this.sell = false
      highWaveClear = true
      this.pingDuoReason = 'macdUpHigh'
    }
    if (highWaveClear) {
      this.disabled = highWaveClear
      btbOpInfo.cancelDisabledStatus = ''
    }
  },
  // 策略限制
  btbStrategyLimit () {
    const opConfig = this.opConfig
    if (opConfig.btbStrategy === 2) {
      // 只做多
      if (this.sell) {
        this.pingDuo = true
        this.pingDuoReason = this.sellReason
      }
      this.pingKong = false
      this.sell = false
    } else if (opConfig.btbStrategy === 3) {
      // 只做空
      if (this.buy) {
        this.pingKong = true
        this.pingKongReason = this.buyReason
      }
      this.buy = false
      this.pingDuo = false
    }
  },
  // 纠缠阶段，但是盈利，那就清掉
  clearIfTangleWithProfit () {
    const hourEma = this.btbItem.hourEmaInfo || {}
    const btbItem = this.btbItem
    const btbOpInfo = this.btbOpInfo
    const minute15EmaInfo = this.btbItem.minute15EmaInfo || {}
    // sg很低，但是盈利
    if (btbItem.minSg < 1) {
      if (btbItem.incomeRate > 1) {
        if (minute15EmaInfo.macd < 0 && minute15EmaInfo.tr < 0 && minute15EmaInfo.kdjDiff < 2) {
          this.pingDuo = true
          btbOpInfo.actionStatus = ''
          this.pingDuoReason = 'clearIfTangleWithProfit'
        }
        if (minute15EmaInfo.macd > 0 && minute15EmaInfo.tr > 0 && minute15EmaInfo.kdjDiff > 2) {
          this.pingKong = true
          this.pingKongReason = 'clearIfTangleWithProfit'
        }
      }
      // 亏损多
      if (btbItem.incomeRate < -1) {
        if (
          hourEma.kdjDiff < 0 &&
          (hourEma.macd < 0 || hourEma.ema5 < hourEma.ema10) &&
          minute15EmaInfo.macd < 0 && minute15EmaInfo.tr < 0 && minute15EmaInfo.kdjDiff < 2
        ) {
          this.pingDuo = true
          btbOpInfo.actionStatus = ''
          this.pingDuoReason = 'clearIfTangleWithProfit-1'
        }
        if (
          hourEma.kdjDiff > 0 &&
          (hourEma.macd > 0 || hourEma.ema5 > hourEma.ema10) &&
          minute15EmaInfo.macd > 0 && minute15EmaInfo.tr > 0 && minute15EmaInfo.kdjDiff > 2
        ) {
          this.pingKong = true
          this.pingKongReason = 'clearIfTangleWithProfit-1'
        }
      }
    }
  },
  clearIfMacdKeepTimesLong () {
    const minute15EmaInfo = this.btbItem.minute15EmaInfo || {}
    const hourEmaInfo = this.btbItem.hourEmaInfo || {}
    if (
      btbAs.ifMacdUpTimes(minute15EmaInfo.emInfoList || [], 12) &&
      minute15EmaInfo.macd > 0 &&
      (minute15EmaInfo.ema10 > minute15EmaInfo.ema20 && minute15EmaInfo.ema5 > minute15EmaInfo.ema10)
    ) {
      this.pingKong = true
      this.pingKongReason = 'clearIfMacdKeepTimesLong'
    }
    if (
      btbAs.ifMacdDownTimes(minute15EmaInfo.emInfoList || [], 12) &&
      minute15EmaInfo.macd < 0 &&
      (minute15EmaInfo.ema10 < minute15EmaInfo.ema20 && minute15EmaInfo.ema5 < minute15EmaInfo.ema10)
    ) {
      this.pingDuo = true
      this.pingDuoReason = 'clearIfMacdKeepTimesLong'
    }
    if (this.btbOpInfo.hourMacdUpKeepLong === 'macdUpKeepLong') {
      if (hourEmaInfo.macd < 0 && minute15EmaInfo.kdjDiff < 0) {
        if (
          minute15EmaInfo.macd < 0 ||
          minute15EmaInfo.ema5 < minute15EmaInfo.ema10
        ) {
          this.pingDuo = true
          this.pingDuoReason = 'clearIfMacdKeepTimesLong-1'
        }
      }
    }
    if (this.btbOpInfo.minute15MacdUpKeepLong === 'macdUpKeepLong') {
      if (minute15EmaInfo.macd < 0 && minute15EmaInfo.kdjDiff < 0) {
        this.pingDuo = true
        this.pingDuoReason = 'clearIfMacdKeepTimesLong-2'
      }
    }
  },
  setSellKdj () {
    const asList = this.btbItem.asList
    const minute15EmaInfo = this.btbItem.minute15EmaInfo || {}
    const diff510 = numberUtil.countDifferenceRate(minute15EmaInfo.ema5, minute15EmaInfo.ema10)
    if (kdjUpKeepTimes(asList, 9) && diff510 > 0.275) {
      this.btbOpInfo.actionStatus = 'sell-kdj'
    }
  },
  setHourSellKdj () {
    const hourEmaInfo = this.btbItem.hourEmaInfo || {}
    if (btbAs.ifKdjUpTimes(hourEmaInfo.emInfoList || [], 15, 0) && hourEmaInfo.kdjDiff > 0) {
      this.btbOpInfo.hourSellKdj = 'sell-kdj'
    }
  },
  setMacdKeepLong () {
    const hourEmaInfo = this.btbItem.hourEmaInfo || {}
    const minute15EmaInfo = this.btbItem.minute15EmaInfo || {}
    if (btbAs.ifMacdUpTimes(hourEmaInfo.emInfoList || [], 23)) {
      this.btbOpInfo.hourMacdUpKeepLong = 'macdUpKeepLong'
    }
    if (btbAs.ifMacdUpTimes(minute15EmaInfo.emInfoList || [], 23)) {
      this.btbOpInfo.minute15MacdUpKeepLong = 'macdUpKeepLong'
    }
  },
  buySellNormal () {
    const btbOpInfo = this.btbOpInfo
    const dayEmaInfo = this.btbItem.dayEmaInfo || {}
    const hour4EmaInfo = this.btbItem.hour4EmaInfo || {}
    const hourEma = this.btbItem.hourEmaInfo || {}
    const minute15EmaInfo = this.btbItem.minute15EmaInfo || {}
    const isEmaM20105 = minute15EmaInfo.ema5 < minute15EmaInfo.ema10 && minute15EmaInfo.ema10 < minute15EmaInfo.ema20
    // 顺
    if (hourEma.ema5 < hourEma.ema20 && hourEma.ema10 < hourEma.ema20) {
      if ((hourEma.macd < 0 || hourEma.kdjDiff < 0) && minute15EmaInfo.kdjDiff < 2) {
        this.pingDuo = true
        this.pingDuoReason = '0-1'
        btbOpInfo.actionStatus = ''
      }
      // 空单盈利多了
      if (this.kongProfitHigh) {
        if (hourEma.macd > 0 || hourEma.tr > 0 || hourEma.kdjDiff > 0) {
          if (minute15EmaInfo.kdjDiff > 2 && (minute15EmaInfo.tr > 0 || minute15EmaInfo.macd > 0)) {
            this.pingKong = true
            this.pingKongReason = '0-2'
          }
        }
        // 15分钟转向就平仓
        if (minute15EmaInfo.kdjDiff > 2 && (minute15EmaInfo.tr > 0 || minute15EmaInfo.macd > 0)) {
          this.pingKong = true
          this.pingKongReason = '0-3'
        }
      }
      // 5和10都在下，可以有平仓，但是不开多
      // 5<10<20
      if (hourEma.ema5 < hourEma.ema10 && hourEma.ema10 < hourEma.ema20) {
        if (
          (hourEma.macd > 0 && hourEma.tr > 0) ||
          // 转涨，并且之前持续跌了很久
          (hourEma.macd > 0 && hourEma.macddd > 15)
        ) {
          if (minute15EmaInfo.tr > 0 && !(minute15EmaInfo.ema5 > minute15EmaInfo.ema10 && minute15EmaInfo.ema5 < minute15EmaInfo.ema20) && minute15EmaInfo.kdjDiff > 2) {
            this.pingKong = true
            this.pingKongReason = '0-4'
          }
        } else {
          if (hourEma.macd < 0) {
            if (minute15EmaInfo.kdjDiff < 2 && !(minute15EmaInfo.tr > 0 || minute15EmaInfo.macd > 0)) {
              this.sell = true
              this.sellRate = 1
              btbOpInfo.actionStatus = ''
              this.sellReason = '0-5'
            }
          }
        }
        if (hourEma.kdjDiff < 0 && hourEma.tr < 0) {
          if (minute15EmaInfo.kdjDiff < 2 && !(minute15EmaInfo.tr > 0 || minute15EmaInfo.macd > 0)) {
            this.sell = true
            this.sellRate = 1
            btbOpInfo.actionStatus = ''
            this.sellReason = '0-6'
          }
        }
        if (hourEma.sg > 1 && hourEma.kdjDiff < 0 && hourEma.macd < 0) {
          if (
            minute15EmaInfo.kdjDiff < 0 &&
            minute15EmaInfo.tr < 0 &&
            minute15EmaInfo.macd < 0
          ) {
            // TODO 为啥这个策略老是亏钱
            this.sell = true
            this.sellRate = 1
            btbOpInfo.actionStatus = ''
            this.sellReason = '0-7'
          }
        }
      } else {
        // 10<5<20
        if (hourEma.macd > 0 && hourEma.tr > 0) {
          if (minute15EmaInfo.tr > 0 && minute15EmaInfo.kdjDiff > 2) {
            this.pingKong = true
            this.pingKongReason = '0-8'
          }
        } else {
          if (hourEma.macd < 0) {
            if (minute15EmaInfo.tr < 0 && minute15EmaInfo.macd < 0 && minute15EmaInfo.kdjDiff < 2) {
              this.sell = true
              this.sellRate = 1
              btbOpInfo.actionStatus = ''
              this.sellReason = '0-9'
            }
          }
        }
        if (hourEma.kdjDiff < 0 && hourEma.tr < 0) {
          if (minute15EmaInfo.tr < 0 && minute15EmaInfo.macd < 0 && minute15EmaInfo.kdjDiff < 2) {
            this.sell = true
            this.sellRate = 1
            btbOpInfo.actionStatus = ''
            this.sellReason = '0-10'
          }
        }
      }
      // 10>20,5>20
    } else if (hourEma.ema5 > hourEma.ema20 && hourEma.ema10 > hourEma.ema20) {
      if (hourEma.kdjDiff > 0 && minute15EmaInfo.kdjDiff > 2) {
        this.pingKong = true
        this.pingKongReason = '0-11'
      }
      // 多单盈利多了
      if (this.duoProfitHigh) {
        if (hourEma.macd < 0 || hourEma.tr < 0 || hourEma.kdjDiff < 0) {
          if (minute15EmaInfo.kdjDiff < 2 && (minute15EmaInfo.tr < 0 || minute15EmaInfo.macd < 0)) {
            this.pingDuo = true
            this.pingDuoReason = '0-12'
          }
        }
        // 15分钟转向就平仓
        if (minute15EmaInfo.kdjDiff < 2 && (minute15EmaInfo.tr < 0 || minute15EmaInfo.macd < 0)) {
          this.pingDuo = true
          this.pingDuoReason = '0-13'
        }
      }
      // 20<10<5
      if (hourEma.ema5 > hourEma.ema10 && hourEma.ema10 > hourEma.ema20) {
        if (hourEma.macd < 0 && hourEma.tr < 0) {
          if (minute15EmaInfo.tr < 0 && minute15EmaInfo.kdjDiff < 2) {
            this.pingDuo = true
            this.pingDuoReason = '0-14'
          }
        } else {
          if (hourEma.macd > 0) {
            if (minute15EmaInfo.kdjDiff >= 2 && !(minute15EmaInfo.tr < 0 || minute15EmaInfo.macd < 0)) {
              this.buy = true
              this.buyRate = 1
              this.buyReason = '0-15'
            }
          }
        }
        if (
          (hourEma.sg > 1 && hourEma.kdjDiff > 0 && hourEma.macd > 0) &&
          (
            (hour4EmaInfo.kdjDiff > 0 && hour4EmaInfo.macd > 0) ||
            (dayEmaInfo.kdjDiff > 0 && dayEmaInfo.macd > 0)
          ) &&
          this.btbIndexTotalInfo.hourAverageScore >= 60
        ) {
          if (
            (minute15EmaInfo.sg > 1 && minute15EmaInfo.kdjDiff >= 2 && minute15EmaInfo.tr > 0 && minute15EmaInfo.macd > 0) &&
            (minute15EmaInfo.ema5 > minute15EmaInfo.ema20 && minute15EmaInfo.ema10 > minute15EmaInfo.ema20)
          ) {
            this.buy = true
            this.buyRate = 1
            this.buyReason = '0-16'
          }
        }
      } else {
        // 20<5<10
        if (hourEma.macd < 0 && hourEma.tr < 0) {
          if (minute15EmaInfo.tr < 0 && minute15EmaInfo.kdjDiff < 2) {
            this.pingDuo = true
            this.pingDuoReason = '0-17'
          }
          // 涨的会比较容易跌
          if (hourEma.kdjDiff < 0) {
            if (minute15EmaInfo.tr < 0 && isEmaM20105 && minute15EmaInfo.macd < 0 && minute15EmaInfo.kdjDiff < 2) {
              this.sell = true
              this.sellRate = 1
              btbOpInfo.actionStatus = ''
              this.sellReason = '0-18'
            }
          }
        } else {
          if (hourEma.macd > 0) {
            if (minute15EmaInfo.tr > 0 && minute15EmaInfo.macd > 0 && minute15EmaInfo.kdjDiff > 2) {
              this.buy = true
              this.buyRate = 1
              this.buyReason = '0-19'
            }
          }
        }
      }
      // 5<20<10，属于下跌的
    } else if (hourEma.ema5 < hourEma.ema20 && hourEma.ema10 > hourEma.ema20) {
      if (minute15EmaInfo.kdjDiff < 2 || minute15EmaInfo.tr < 0 || minute15EmaInfo.macd < 0) {
        this.pingDuo = true
        btbOpInfo.actionStatus = ''
        this.pingDuoReason = '0-20'
      }
      if (hourEma.kdjDiff < 0) {
        if (minute15EmaInfo.tr < 0 && minute15EmaInfo.macd < 0 && minute15EmaInfo.kdjDiff < 2) {
          this.sell = true
          this.sellRate = 1
          btbOpInfo.actionStatus = ''
          this.sellReason = '0-21'
        }
      }
      // 10<20<5，属于上涨的
    } else if (hourEma.ema5 > hourEma.ema20 && hourEma.ema10 < hourEma.ema20) {
      if (minute15EmaInfo.kdjDiff > 2 || minute15EmaInfo.tr > 0 || minute15EmaInfo.macd > 0) {
        this.pingKong = true
        this.pingKongReason = '0-22'
      }
      if (hourEma.kdjDiff > 0) {
        if (minute15EmaInfo.tr > 0 && minute15EmaInfo.macd > 0 && minute15EmaInfo.kdjDiff > 2) {
          this.buy = true
          this.buyRate = 1
          this.buyReason = '0-23'
        }
      } else {
        if (minute15EmaInfo.tr < 0 && minute15EmaInfo.macd < 0 && minute15EmaInfo.kdjDiff < 2) {
          this.pingDuo = true
          btbOpInfo.actionStatus = ''
          this.pingDuoReason = '0-24'
        }
      }
    }
  },
  clearIfHyDisabled () {
    // 持仓是空单，那么平空
    if (this.btbItem.usdt < -5) {
      this.pingKong = true
      this.pingKongReason = 'clearIfHyDisabled'
    }
    // 持仓是多单，那么平多
    if (this.btbItem.usdt > 5) {
      this.pingDuo = true
      this.pingDuoReason = 'clearIfHyDisabled'
    }
  },
  // 解除禁用
  cancelDisabled () {
    const hourEma = this.btbItem.hourEmaInfo || {}
    if (hourEma.sg < 1) {
      this.btbOpInfo.cancelDisabledStatus = '1'
    } else {
      if (this.btbOpInfo.cancelDisabledStatus === '1') {
        this.btbOpInfo.cancelDisabledStatus = '2'
      }
    }
    if (this.btbOpInfo.cancelDisabledStatus === '2') {
      this.btbOpInfo.cancelDisabledStatus = ''
      this.disabled = false
    }
  },
  newIndexBuySell (reKey) {
    reKey = reKey || 'newIndexBuySell'
    const {
      isHour4HasEmaInfo
    } = this.indexFlagInfo
    const hourEmaInfo = this.btbItem.hourEmaInfo || {}
    const hour4EmaInfo = this.btbItem.hour4EmaInfo || {}
    const minute15EmaInfo = this.btbItem.minute15EmaInfo || {}
    if (hourEmaInfo.isDuo) {
      const hour4Ok = !isHour4HasEmaInfo ||
        (
          hour4EmaInfo.isEm5Increase && hour4EmaInfo.isEm10Increase && hour4EmaInfo.isEm20Increase &&
          hour4EmaInfo.macd > 0 && hour4EmaInfo.isMacdIncrease &&
          hour4EmaInfo.kdjDiff > 0 && hour4EmaInfo.isKdjIncrease
        )
      if (
        hour4Ok &&
        (hourEmaInfo.isLongDuo && hourEmaInfo.isEm5Increase && hourEmaInfo.isEm10Increase && hourEmaInfo.isEm20Increase) &&
        (minute15EmaInfo.isDuo && minute15EmaInfo.isAllIncrease) &&
        !(hourEmaInfo.kdjud === 1 && hourEmaInfo.nowRatio5 > 0.5)
      ) {
        this.setBuy(`${reKey}-1`)
      }
    } else {
      this.setPingDuo(`${reKey}-2`)
    }
    if (hourEmaInfo.isKong) {
      const hour4Ok = !isHour4HasEmaInfo ||
        (
          hour4EmaInfo.isEm5Decline && hour4EmaInfo.isEm10Decline && hour4EmaInfo.isEm20Decline &&
          hour4EmaInfo.macd < 0 && hour4EmaInfo.isMacdDecline &&
          hour4EmaInfo.kdjDiff < 0 && hour4EmaInfo.isKdjDecline
        )
      if (
        hour4Ok &&
        (hourEmaInfo.isLongKong && hourEmaInfo.isEm5Decline && hourEmaInfo.isEm10Decline && hourEmaInfo.isEm20Decline) &&
        (minute15EmaInfo.isKong && minute15EmaInfo.isAllDecline) &&
        !(hourEmaInfo.kdjdd === 1 && hourEmaInfo.nowRatio5 > 0.5)
      ) {
        this.setSell(`${reKey}-3`)
      }
    } else {
      this.setPingKong(`${reKey}-4`)
    }
  },
  noBuySellIfWaveLow () {
    const dayEmaInfo = this.btbItem.dayEmaInfo || {}
    const hourEmaInfo = this.btbItem.hourEmaInfo || {}
    const hour4EmaInfo = this.btbItem.hour4EmaInfo || {}
    const minute15EmaInfo = this.btbItem.minute15EmaInfo || {}
    if (dayEmaInfo.days5RealWave < 0.1 || dayEmaInfo.days5MaxWave < 0.1) {
      this.setNoBuy()
      this.setNoSell()
    }
    if (hourEmaInfo.days5RealWave < 0.1 || hourEmaInfo.days5MaxWave < 0.1) {
      this.setNoBuy()
      this.setNoSell()
    }
    if (minute15EmaInfo.days5RealWave < 0.1 || minute15EmaInfo.days5MaxWave < 0.1) {
      this.setNoBuy()
      this.setNoSell()
    }
    if (
      minute15EmaInfo.days5RealWave < 0.4 ||
      hourEmaInfo.days5RealWave < 0.4 ||
      hour4EmaInfo.days5RealWave < 0.4
    ) {
      this.setNoBuy()
      this.setNoSell()
    }
    if (
      minute15EmaInfo.nowRatio5 > 0.6 ||
      hourEmaInfo.nowRatio5 > 0.6
    ) {
      if (hourEmaInfo.kdjDiff < 0) {
        this.setNoBuy()
      }
      if (hourEmaInfo.kdjDiff > 0) {
        this.setNoSell()
      }
    }
    if (hourEmaInfo.sg > 10) {
      this.setNoBuy()
      this.setNoSell()
    }
    if (hourEmaInfo.nowRatio5 > 0.5) {
      if (
        hourEmaInfo.macdud === 1 &&
        hour4EmaInfo.macdud === 1 &&
        hour4EmaInfo.kdjud === 1
      ) {
        this.setNoBuy()
      }
      if (
        hourEmaInfo.macddd === 1 &&
        hour4EmaInfo.macddd === 1 &&
        hour4EmaInfo.kdjdd === 1
      ) {
        this.setNoSell()
      }
    }
    if (
      hourEmaInfo.nowRatio5 > 0.5 &&
      hour4EmaInfo.nowRatio5 > 0.5 &&
      hour4EmaInfo.days10MaxWave < 0.1 &&
      dayEmaInfo.days10MaxWave < 0.1 &&
      (hour4EmaInfo.isBuffer || hour4EmaInfo.isReadjust) &&
      (dayEmaInfo.isBuffer || dayEmaInfo.isReadjust)
    ) {
      if (hourEmaInfo.isLongDuo && hour4EmaInfo.isLongKong) {
        this.setNoBuy()
      }
      if (hourEmaInfo.isLongKong && hour4EmaInfo.isLongDuo) {
        this.setNoSell()
      }
    }
    if (
      hourEmaInfo.nowRatio5 > 0.5 &&
      hour4EmaInfo.nowRatio5 > 0.5 &&
      dayEmaInfo.days10MaxWave < 0.1 &&
      (dayEmaInfo.isBuffer || dayEmaInfo.isReadjust)
    ) {
      if (dayEmaInfo.kdjud === 1) {
        this.setNoBuy()
      }
      if (dayEmaInfo.kdjdd === 1) {
        this.setNoSell()
      }
    }
    if (
      this.btbIndexTotalInfo.positionFen < 40 &&
      minute15EmaInfo.nowRatio5 > 0.5 &&
      (hourEmaInfo.nowRatio5 > 0.5 && hourEmaInfo.macd > 0 && hourEmaInfo.macdud <= 2) &&
      (hour4EmaInfo.isReadjust && hour4EmaInfo.macd < 0 && hour4EmaInfo.kdjDiff > 0 && hour4EmaInfo.kdjud <= 2)
    ) {
      this.setNoBuy()
    }
    if (
      this.btbIndexTotalInfo.positionFen < 60 &&
      hour4EmaInfo.nowRatio5 > 0.5 &&
      hour4EmaInfo.isReadjust &&
      (hour4EmaInfo.macd < 0 && hour4EmaInfo.kdjDiff > 0 && hour4EmaInfo.kdjud <= 2)
    ) {
      this.setNoBuy()
    }
    if (dayEmaInfo.sg > 12) {
      if (
        (dayEmaInfo.ema10 > dayEmaInfo.ema20 && dayEmaInfo.ema5 > dayEmaInfo.ema10) &&
        dayEmaInfo.kdjDiff < 0
      ) {
        this.setNoBuy()
        this.setNoSell()
      }
      if (
        (dayEmaInfo.ema10 < dayEmaInfo.ema20 && dayEmaInfo.ema5 < dayEmaInfo.ema10) &&
        dayEmaInfo.kdjDiff > 0
      ) {
        this.setNoBuy()
        this.setNoSell()
      }
    }
    if (
      minute15EmaInfo.days2RealMaxWave < 0.25
    ) {
      this.setNoBuy()
      this.setNoSell()
    }
    if (
      (dayEmaInfo.isLongDuo && dayEmaInfo.kdjDiff > 0 && dayEmaInfo.sg > 8) &&
      dayEmaInfo.macdud > 5 &&
      btbAs.ifFuncTimes((em) => {
        return em.ema5 > em.ema20 && em.ema10 > em.ema20
      }, dayEmaInfo.emInfoList || [], 10) &&
      (hour4EmaInfo.isLongDuo && hour4EmaInfo.kdjDiff > 0 && hour4EmaInfo.sg > 4) &&
      hour4EmaInfo.macdud > 5 &&
      btbAs.ifFuncTimes((em) => {
        return em.ema5 > em.ema20 && em.ema10 > em.ema20
      }, hour4EmaInfo.emInfoList || [], 10) &&
      (hourEmaInfo.isLongDuo && hourEmaInfo.kdjDiff > 0 && hourEmaInfo.sg > 2) &&
      hourEmaInfo.macdud > 5 &&
      btbAs.ifFuncTimes((em) => {
        return em.ema5 > em.ema20 && em.ema10 > em.ema20
      }, hourEmaInfo.emInfoList || [], 10) &&
      (minute15EmaInfo.ema5 > minute15EmaInfo.ema10 && minute15EmaInfo.ema10 > minute15EmaInfo.ema20)
    ) {
      this.setNoPingDuo()
    }
    if (
      (dayEmaInfo.isLongKong && dayEmaInfo.kdjDiff < 0 && dayEmaInfo.sg > 8) &&
      dayEmaInfo.macddd > 5 &&
      btbAs.ifFuncTimes((em) => {
        return em.ema5 < em.ema20 && em.ema10 < em.ema20
      }, dayEmaInfo.emInfoList || [], 10) &&
      (hour4EmaInfo.isLongKong && hour4EmaInfo.kdjDiff < 0 && hour4EmaInfo.sg > 4) &&
      hour4EmaInfo.macddd > 5 &&
      btbAs.ifFuncTimes((em) => {
        return em.ema5 < em.ema20 && em.ema10 < em.ema20
      }, hour4EmaInfo.emInfoList || [], 10) &&
      (hourEmaInfo.isLongKong && hourEmaInfo.kdjDiff < 0 && hourEmaInfo.sg > 2) &&
      hourEmaInfo.macddd > 5 &&
      btbAs.ifFuncTimes((em) => {
        return em.ema5 < em.ema20 && em.ema10 < em.ema20
      }, hourEmaInfo.emInfoList || [], 10) &&
      (minute15EmaInfo.ema5 < minute15EmaInfo.ema10 && minute15EmaInfo.ema10 < minute15EmaInfo.ema20)
    ) {
      this.setNoPingKong()
    }
    if (
      hourEmaInfo.isReadjust &&
      hourEmaInfo.macd < 0 &&
      hourEmaInfo.kdjDiff > 0 &&
      hourEmaInfo.kdjud < 3 &&
      hourEmaInfo.nowRatio5 > 0.6 &&
      hour4EmaInfo.kdjDiff > 0 &&
      hour4EmaInfo.kdjud === 1
    ) {
      this.setNoBuy()
    }
    if (
      (hour4EmaInfo.kdjud === 1 || hour4EmaInfo.macdud === 1) &&
      hour4EmaInfo.sg < 2 &&
      (hourEmaInfo.kdjud === 1 || hourEmaInfo.macdud === 1) &&
      hourEmaInfo.sg < 1.5 &&
      hourEmaInfo.nowRatio5 > 0.5 &&
      minute15EmaInfo.nowRatio5 > 0.5
    ) {
      this.setNoBuy()
    }
    if (
      dayEmaInfo.kdjud === 1 &&
      hour4EmaInfo.nowRatio5 > 0.5 &&
      hour4EmaInfo.kdjDiff < 0 &&
      minute15EmaInfo.kdjud === 1 &&
      minute15EmaInfo.nowRatio5 > 0.5
    ) {
      this.setNoBuy()
    }
    // 全是第一个
    if (
      (hour4EmaInfo.kdjud === 1 || hour4EmaInfo.macdud === 1) &&
      (hourEmaInfo.kdjud === 1 || hourEmaInfo.macdud === 1) &&
      (minute15EmaInfo.kdjud === 1 || minute15EmaInfo.macdud === 1)
    ) {
      this.setNoBuy()
    }
    if (
      (hourEmaInfo.nowRatio5 > 0.5 && hourEmaInfo.macdud === 1) &&
      (minute15EmaInfo.nowRatio5 > 0.5 && minute15EmaInfo.macdud === 1)
    ) {
      this.setNoBuy()
    }
  }
}
